\version "2.14.2"
\include "english.ly"

\paper {
 indent = #0
}

\header {
  title = "<%= self.title %>"
  composer = "<%= self.composer %>"
  arranger = "<%= self.arranger %>"
  instrument = "<%= self.instrument %>"
}

%-----------------------------------------------------------------------
% Chord Sets

<% definitions(Gitara::Node::ChordSet).each do |chord_set| %>
<%= Gitara.render('chord_set', chord_set) %>
<% end %>

%-----------------------------------------------------------------------
% Bars

<% definitions(Gitara::Node::Bar).each do |bar| %>
<%= Gitara.render('bar', bar) %>
<% end %>

%-----------------------------------------------------------------------
% Lines

<% definitions(Gitara::Node::Line).each do |line| %>
<%= Gitara.render('line', line) %>
<% end %>

%-----------------------------------------------------------------------
% Stanzas

<% definitions(Gitara::Node::Stanza).each do |stanza| %>
<%= Gitara.render('stanza', stanza) %>
<% end %>

%-----------------------------------------------------------------------
% Scores

<% definitions(Gitara::Node::Score).each do |score| %>
<%= Gitara.render('score', score) %>
<% end %>

%-----------------------------------------------------------------------
% Voices

<% voices.each do |voice| %>
<%= Gitara.render('voice', voice) %>
<% end %>

%-----------------------------------------------------------------------
% Stanza Headings

stanzaHeadings = { 
<%- if playable_child.descendants(Gitara::Node::Stanza).any? %>
<%= playable_child.stanza_version.call_name %> 
<% end %>
}

%-----------------------------------------------------------------------
% Chord Headings

chordHeadings = { <%= playable_child.chorded.call_name %> }

%-----------------------------------------------------------------------

\score {
  \new StaffGroup <<
    \new Staff <<
      <%= Gitara.render('tab_time', self) %>
      <%= Gitara.render('tab_tempo', self) %>
      \clef "treble_8"

      \new ChordNames {
        \chordHeadings
      }

      \new Voice \with { \remove Rest_engraver } {
        \stanzaHeadings
      }

      <% voices.each do |voice| %>
      \new Voice {
        <%= self.key && "\\key #{self.key}" %>
        <%= voice.stem_type %>
        <%= voice.call_name %>
      }
      <% end %>
    >>

    \new TabStaff <<
      <%= self.string_tunings && "\\set TabStaff.stringTunings = #{self.string_tunings}" %>
      <% voices.each do |voice| %>
      \new TabVoice {
        \slurUp
        <%= voice.call_name %>
      }
      <% end %>
    >>
  >>

  \layout {
    \context { \Staff
      \override TimeSignature #'style = #'numbered
      \override StringNumber #'transparent = ##t
    }
    \context { \TabStaff
      \override TimeSignature #'style = #'numbered
    }
    \context { \Voice
      \remove Slur_engraver
    }
    \context { \TabVoice
      \remove Dots_engraver
      \remove Stem_engraver
      \remove Rest_engraver
    }
  }
}

% showLastLength = R1*4
\score {
  \new Staff \with {midiInstrument = #"<%= self.midi_instrument %>"} <<
    <%= Gitara.render('tab_tempo', self) %>
    \clef "treble_8"

    <% voices.each do |voice| %>
    \new Voice {
      \unfoldRepeats {
        <%= voice.call_name %>
      }
    }
    <% end %>
  >>

  \midi {}
}
